package com.dianxun.exam.adapter.provider;

import android.widget.RadioGroup;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.dianxun.exam.R;
import com.dianxun.exam.common.AppKeyManager;
import com.dianxun.exam.entity.JudgmentListBean;
import com.dianxun.exam.entity.TypeEntity;

/**
 * 判断题
 */
public class JudgmentProvider extends BaseItemProvider<TypeEntity, BaseViewHolder> {

    @Override
    public int viewType() {
        return AppKeyManager.TYPE_JUDGMENT;
    }

    @Override
    public int layout() {
        return R.layout.item_exam_judgment;
    }

    @Override
    public void convert(BaseViewHolder helper, final TypeEntity data, int position) {
        JudgmentListBean entity = (JudgmentListBean) data;
        helper.setText(R.id.tv_title, position + ".  " + entity.getItemName() + "（" + entity.getScore() + "分）");
        RadioGroup rg_judgment = helper.getView(R.id.rg_judgment);
        rg_judgment.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_true:
                        ((JudgmentListBean) data).setAnswer(1);
                        break;
                    case R.id.rb_false:
                        ((JudgmentListBean) data).setAnswer(0);
                        break;
                }
            }
        });
        if (entity.getAnswer() == 1) {
            rg_judgment.check(R.id.rb_true);
        } else if (entity.getAnswer() == 0) {
            rg_judgment.check(R.id.rb_false);
        }
    }

    @Override
    public void onClick(BaseViewHolder helper, TypeEntity data, int position) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder helper, TypeEntity data, int position) {
        return true;
    }
}
